package com.fulihui.systemcore.dal.convertor;

import com.fulihui.systemcore.condition.WechatConfigCondition;
import com.fulihui.systemcore.dal.dataobj.WechatConfig;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 *
 * @author Created by Willard.Hu on 2016/6/2.
 */
public class WechatConfigConv {

    public static WechatConfig toDO(WechatConfigCondition condition) {
        if (condition == null) {
            return null;
        }
        WechatConfig wechatConfigDO = new WechatConfig();
        wechatConfigDO.setConfigCode(condition.getConfigCode());
        if (condition.getEnvType() != null) {
            wechatConfigDO.setEnvType(condition.getEnvType().getCode());
        }
        wechatConfigDO.setAppId(condition.getAppId());
        return wechatConfigDO;
    }

    public static com.fulihui.systemcore.dto.WechatConfig toDTO(WechatConfig wechatConfigDO) {
        if (wechatConfigDO == null) {
            return null;
        }
        com.fulihui.systemcore.dto.WechatConfig wechatConfig = new com.fulihui.systemcore.dto.WechatConfig();
        wechatConfig.setAppID(wechatConfigDO.getAppId());
        wechatConfig.setConfigCode(wechatConfigDO.getConfigCode());
        wechatConfig.setAppsecret(wechatConfigDO.getAppsecret());
        wechatConfig.setMchId(wechatConfigDO.getMchId());
        wechatConfig.setSignKey(wechatConfigDO.getSignKey());
        wechatConfig.setCertFile(wechatConfigDO.getCertFile());
        wechatConfig.setEncodingAesKey(wechatConfigDO.getEncodingAesKey());
        wechatConfig.setToken(wechatConfigDO.getToken());
        return wechatConfig;
    }

    public static List<com.fulihui.systemcore.dto.WechatConfig> toList(List<WechatConfig> doList) {
        if (CollectionUtils.isEmpty(doList)) {
            return Collections.emptyList();
        }
        return doList.stream().map(WechatConfigConv::toDTO).collect(Collectors.toList());
    }

    // TODO more ..

}
